package demo0623;

import java.util.Scanner;

public class SalaryCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 1. 显示欢迎界面和菜单
        System.out.println("=== 工资计算器系统 ===");
        System.out.println("1. 计算月薪");
        System.out.println("2. 计算年薪");
        System.out.println("0. 退出系统");

        // 2. 接收菜单选择并验证
        int choice;
        while (true) {
            System.out.print("请选择操作类型(0-2): ");
            choice = scanner.nextInt();
            if (choice >= 0 && choice <= 2) {
                break;
            }
            System.out.println("输入无效，请重新输入！");
        }

        if (choice == 0) {
            System.out.println("感谢使用，再见！");
            return;
        }

        scanner.nextLine(); // 清除缓冲区

        // 3. 接收职工个人信息
        System.out.println("\n=== 请输入个人信息 ===");
        System.out.print("姓名: ");
        String name = scanner.nextLine();
        System.out.print("工号: ");
        String id = scanner.nextLine();
        System.out.print("部门: ");
        String department = scanner.nextLine();

        // 4. 接收工资信息
        System.out.println("\n=== 请输入工资信息 ===");
        System.out.print("基本工资: ");
        double baseSalary = scanner.nextDouble();
        System.out.print("岗位津贴: ");
        double allowance = scanner.nextDouble();
        System.out.print("绩效奖金: ");
        double bonus = scanner.nextDouble();

        // 5. 计算工资
        double monthlySalary = baseSalary + allowance + bonus;
        double totalSalary;
        int months = 1;

        if (choice == 2) {
            System.out.print("\n请输入计算月份数: ");
            months = scanner.nextInt();
            if (months < 1 || months > 12) {
                System.out.println("月份数应在1-12之间，已自动调整为12个月");
                months = 12;
            }
        }

        totalSalary = monthlySalary * months;

        // 6. 显示计算结果
        System.out.println("\n=== 工资计算结果 ===");
        System.out.println("姓名: " + name);
        System.out.println("工号: " + id);
        System.out.println("部门: " + department);
        System.out.println("基本工资: " + baseSalary);
        System.out.println("岗位津贴: " + allowance);
        System.out.println("绩效奖金: " + bonus);
        System.out.println("月薪: " + monthlySalary);

        if (choice == 1) {
            System.out.println("计算结果: 月薪 = " + monthlySalary);
        } else {
            System.out.println("计算月份: " + months + "个月");
            System.out.println("计算结果: 年薪 = " + totalSalary);
        }

        scanner.close();
    }
}

